package main

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

func main2() {
	file0, err := ioutil.ReadFile("E:\\application\\开发环境归档\\omc-prometheus-alert\\overlays\\tempnode\\tempregion\\omc-prometheus-alert-0-rule.yaml")
	if err != nil {
		log.Fatalf("Failed to read file: %v", err)
	}
	file1, err := ioutil.ReadFile("E:\\application\\开发环境归档\\omc-prometheus-alert\\overlays\\tempnode\\tempregion\\omc-prometheus-alert-1-rule.yaml")
	if err != nil {
		log.Fatalf("Failed to read file: %v", err)
	}

	// Parse the YAML file into the Config struct
	var alertRule AlertRule
	var alertRule0 AlertRule
	var alertRule1 AlertRule
	err = yaml.Unmarshal(file0, &alertRule0)
	if err != nil {
		log.Fatalf("Failed to parse YAML: %v", err)
	}

	alertRule.Groups = append(alertRule.Groups, alertRule0.Groups...)

	err = yaml.Unmarshal(file1, &alertRule1)
	if err != nil {
		log.Fatalf("Failed to parse YAML: %v", err)
	}
	alertRule.Groups = append(alertRule.Groups, alertRule1.Groups...)

	// Access the data from the Config struct
	fmt.Println(alertRule0.Groups[0].Name)
	fmt.Println(alertRule0.Groups[0].Rules[0].Alert)
	fmt.Println(alertRule0.Groups[0].Rules[0].Annotations["value"])
	fmt.Println(alertRule0.Groups[0].Rules[0].Labels["rule_id"])
	fmt.Println(alertRule0.Groups[0].Rules[0].Labels["__replica__"])

	yamlData, err := yaml.Marshal(&alertRule)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(yamlData))

}
